package com.catmiao.spark.rdd.operator.transform

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title: RDD_Operator_01_transform
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/2/2 11:48
 */
object RDD_Operator_04_transform_test {

  def main(args: Array[String]): Unit = {
    val sparkCon = new SparkConf().setMaster("local[*]").setAppName("rdd")

    val sparkContext = new SparkContext(sparkCon)


    val rdd = sparkContext.makeRDD(List(
      List(1, 2),
      6,
      List(3, 4),
      "9874"
    ))


    val flatRdd = rdd.flatMap(
      data => {
        data match {
          case list: List[_] => list
          case str: String => List(str.toInt)
          case num: Int => List(num)
        }
      }
    )

    flatRdd.collect().foreach(println)



    sparkContext.stop()
  }

}
